<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #create_time="{ record }">
        {{ tool.dateFormat(record.create_time, 'yyyy-MM-dd hh:mm:ss', '-') }}
      </template>
      <template #thumb="{ record }">
        <a-avatar shape="square">
          <img :src="record.thumb" style="object-fit: cover" />
        </a-avatar>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import infoSingle from '@/api/info/infoSingle'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  infoSingle.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  infoSingle.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'us_info_single',
  rowSelection: {
    showCheckedAll: true
  },
  bordered:{ wrapper: true, cell: true },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: infoSingle.getList,
  recycleApi: infoSingle.getRecycleList,
  add: {
    show: true,
    api: infoSingle.save,
    auth: ['info:single:save']
  },
  edit: {
    show: true,
    api: infoSingle.update,
    auth: ['info:single:update']
  },
  delete: {
    show: true,
    api: infoSingle.deletes,
    auth: ['info:single:delete'],
    realApi: infoSingle.realDeletes,
    realAuth: ['info:single:realDeletes']
  },
  recovery: {
    show: true,
    api: infoSingle.recoverys,
    auth: ['info:single:recovery']
  },
  import: {
    show: true,
    url: 'info/single/import',
    templateUrl: 'info/single/downloadTemplate',
    auth: ['info:single:import']
  },
  export: {
    show: true,
    url: 'info/single/export',
    auth: ['info:single:export']
  }
})

const columns = reactive([
  {
    title: "ID",
    width:80,
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "标题",
    width:260,
    dataIndex: "title",
    formType: "input",
    search: true
  },
  {
    title: "key",
    width:260,
    dataIndex: "key",
    formType: "input",
    search: false
  },
  {
    title: "摘要",
    dataIndex: "summary",
    formType: "textarea",
    hide:true
  },
  {
    title: "缩略图",
    dataIndex: "thumb",
    formType: "upload",
    onlyData: true,
    returnType: "url",
    multiple: false,
    chunk: false,
    type: "image"
  },
  {
    title: "视频",
    dataIndex: "video_file",
    formType: "upload",
    onlyData: true,
    returnType: "url",
    multiple: false,
    chunk: false,
    type: "file"
  },
  {
    title: "内容",
    dataIndex: "content",
    formType: "editor",
    hide: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    formType: "range",
    width:180,
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'info:single' } </script>